﻿<%@ Page Language="C#" AutoEventWireup="true"  MasterPageFile="/_layouts/HtAdmin.master" Inherits="ProjectHT.YKDGVB2012.Core.Webpage.DanhsachGopy,ProjectHT.YKDGVB2012.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=69db40eb91817252" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Import Namespace="Microsoft.SharePoint" %> 
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
<%@ register tagprefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI, Version=2012.2.607.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" %>

<asp:Content ContentPlaceHolderID="PlaceHolderMain" ID="content1" runat="server">
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
	<script type="text/javascript">
		var arr;
		var idarray = "";
		var cancelDropDownClosing = false;
		function RowContextMenu(sender, eventArgs) {
			var menu = window.$find("<%=grPortalListMenu.ClientID %>");

			var evt = eventArgs.get_domEvent();

			if (evt.target.tagName == "INPUT" || evt.target.tagName == "A") {
				return;
			}

			var index = eventArgs.get_itemIndexHierarchical();
			document.getElementById("radGridClickedRowIndex").value = index;

			sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);

			menu.show(evt);

			evt.cancelBubble = true;
			evt.returnValue = false;

			if (evt.stopPropagation) {
				evt.stopPropagation();
				evt.preventDefault();
			}
		}
		function onDropDownClosing(sender, args) {
			cancelDropDownClosing = false;
		}

		function pageLoad() {
			window.$telerik.$('#RadComboBox1_DropDown .rcbList li').click(function (e) {
				e.cancelBubble = true;
				if (e.stopPropagation) {
					e.stopPropagation();
				}
			});
		}
		function OnClientDropDownClosingHandler(sender, e) {
			//do not close the second combo if 
			//a checkbox from the first is clicked
			e.set_cancel(cancelDropDownClosing);
		}
		function ItemClicked(sender, args) {

			var menuItemValue = args.get_item().get_value();
			if (menuItemValue == "Edit") {
				window.radopen("/_layouts/HaTinh_Portal/ContentLoader.aspx?edm=1&rots=cmmr&ids=" + arr, "RadWindow1").set_title("Sửa nội dung");
			} else if (menuItemValue == "View") {
				var edurl = "/Administrator/ContentLoader.aspx?usc=2&rots=list&Id=" + arr;
				window.radopen(edurl);
			}

		}

		function OnclientClicked(sender, args) {

			var item = args.get_item().get_value();

			//var getquery = $.parseQuerystring().mos;
			
			switch (item) {
				case "Addnew":
					window.radopen("/_layouts/HaTinh_Portal/ContentLoader.aspx?edm=0&rots=crm", "RadWindow1").set_title("Thêm văn bản mới");
					break;
				case "Delete":
					DeleteItem(idarray);
					break;
				case "Reload":
					var masterTable = window.$find("<%= _raddtGrid.ClientID %>").get_masterTableView();
					masterTable.rebind();
					break;
			}
		}

		function DeleteItem(arrayid) {
			if (arrayid != "") {
				window.Message.ask("Bạn muốn xóa bản ghi này.", function (val) {
					if (val == "Y") {
						$.ajax({
							url: "/_layouts/Handler/MainHanlder.ashx?act=cmd",
							type: "POST",
							data: { "ids": idarray },
							success: function (context) {
								var js = $.parseJSON(context);
								Message.alert(js.content, function () {
									location.reload();
								}, "");
							}
						});
					}
				}, "", "");
			} else {
				window.Message.alert("Hãy chọn bản ghi để xóa!", function () { }, "Đóng");
			}
		}
		//get Item Id 
		function onclick(sender, args) {
			var index = args.get_item().get_displayIndex();
			var row = sender.get_dataItems()[index];
			var idCell = sender.getCellByColumnUniqueName(row, 'ID');
			arr = parseInt(idCell.innerHTML);
			alert(arr);
		}
		function Onrowselected(sender, args) {
			var id = args.getDataKeyValue("ID");
			arr = id;
			idarray += id + ",";
			return arr;
		}
		function clientClose(arg) {
			var masterTable = window.$find("<%= _raddtGrid.ClientID %>").get_masterTableView();
			masterTable.rebind();
		}
		function StopPropagation(e) {
			//cancel bubbling
			e.cancelBubble = true;
			if (e.stopPropagation) {
				e.stopPropagation();
			}
		}

		function OnrowDeselect(sender, args) {

			var strroot = idarray.toString();
			var db = Onrowselected(sender, args);
			var find = db.toString() + ",";
			idarray = "";
			idarray = strroot.replace(new RegExp(find), "");
		}
		function OnClientNodeClickingHandler(sender, e, parrentid) {
			var node = e.get_node();
			//check if we have clicked on a Make
			if (node.get_category() == "Make") {
				node.toggle();
			}
			else {
				//find the combobox, set its text and close it
				var combo = window.$find(parrentid);
				combo.set_text(node.get_text());
				cancelDropDownClosing = false;
				combo.hideDropDown();
			}
		}

	</script>	
</telerik:RadCodeBlock>

	<article class="module width_full">
			<header><h3>Danh sách văn bản dự thảo luật</h3></header>
			<div class="module_content">
				<telerik:RadWindowManager ID="RadWindowManager1" ShowContentDuringLoad="True" VisibleStatusbar="false"
					ReloadOnShow="true" runat="server" OnClientClose="clientClose" EnableShadow="true">
					<Windows>
						<telerik:RadWindow ID="RadWindow1" Width="620" Height="520" runat="server" Modal="True" Behaviors="Close,Reload" />
						<telerik:RadWindow ID="RadWindow2" Width="600" Height="580" runat="server" Behaviors="Close,Reload,Maximize" Modal="True" />
					</Windows>
				</telerik:RadWindowManager>
			<telerik:RadToolBar runat="server" ID="toolbar1" Width="100%" OnClientButtonClicked="OnclientClicked" >
					<Items>
						<%--<telerik:RadToolBarButton Value="Addnew" runat="server" ImageUrl="/_Layouts/1033/Icon/add.png" />
						<telerik:RadToolBarButton IsSeparator="true" />--%>
						<telerik:RadToolBarButton Value="Delete" runat="server" ImageUrl="/_Layouts/1033/Icon/delete.png" />
						<telerik:RadToolBarButton IsSeparator="true" />
						<telerik:RadToolBarButton Value="Reload" runat="server" ImageUrl="/_Layouts/1033/Icon/arrow_refresh.png" />
						<telerik:RadToolBarButton IsSeparator="true" />
					</Items>
				</telerik:RadToolBar>
				<telerik:RadAjaxPanel runat="server" ID="ajaxpanel">
				
				<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default" />
				<input type="hidden" id="radGridClickedRowIndex" name="radGridClickedRowIndex" />
				<telerik:RadGrid ID="_raddtGrid" AllowPaging="True" PageSize="10" AllowMultiRowSelection="True"
					AllowSorting="True" AutoGenerateColumns="False" AllowFilteringByColumn="True"
					runat="server" CellSpacing="0" GridLines="None" ShowGroupPanel="False">					
					<ClientSettings AllowGroupExpandCollapse="False" EnableRowHoverStyle="True" AllowDragToGroup="True">
						<ClientEvents OnRowContextMenu="RowContextMenu"></ClientEvents>
						<ClientEvents OnRowSelected="Onrowselected"></ClientEvents>
						<ClientEvents OnRowDeselected="OnrowDeselect"></ClientEvents>
						<Selecting AllowRowSelect="True"></Selecting>
					</ClientSettings>
					<MasterTableView ClientDataKeyNames="ID" AllowMultiColumnSorting="True">
					<GroupHeaderTemplate>
						Dự thảo văn bản : <%#GetTitle(Eval("IDMain").ToString())%>
						</GroupHeaderTemplate>					
						<Columns>
							<telerik:GridClientSelectColumn HeaderStyle-Width="30px">
								<HeaderStyle Width="30px" />
							</telerik:GridClientSelectColumn>	
							<telerik:GridTemplateColumn HeaderText="Đính kèm" AllowFiltering="false">
							<ItemTemplate>
							 <%#GetAttach(Eval("ID").ToString())%>
							</ItemTemplate>							
							</telerik:GridTemplateColumn>		
							<telerik:GridBoundColumn DataField="Title" HeaderStyle-Width="350px" HeaderText="Tiêu đề" AllowFiltering="false"  UniqueName="Title" />
							<telerik:GridBoundColumn DataField="IDMain" HeaderStyle-Width="350px" HeaderText="MainId" Display="false" AllowFiltering="false"  UniqueName="IDMain" />
							<telerik:GridBoundColumn DataField="Email" HeaderStyle-Width="350px" HeaderText="Email" UniqueName="Email" AllowFiltering="false" />
							<telerik:GridBoundColumn DataField="PhoneNumber" HeaderStyle-Width="350px" HeaderText="Số điện thoại" AllowFiltering="false" UniqueName="PhoneNumber" />							
							<%--<telerik:GridDateTimeColumn DataField="CreatedDate" FilterControlWidth="150" DataFormatString="{0:dd/MM/yyyy}"  UniqueName="CreatedDate" HeaderText="Ngày đăng" />--%>
							<telerik:GridDateTimeColumn DataField="CreatedDate" FilterControlWidth="150" DataFormatString="{0:dd/MM/yyyy}" UniqueName="CreatedDate" HeaderText="Ngày đăng" />
							<telerik:GridCheckBoxColumn DataField="Statust" HeaderStyle-Width="80px" AllowFiltering="False" HeaderText="Công bố" UniqueName="Statust" />
				 		    
						</Columns>

					</MasterTableView>

				</telerik:RadGrid>
				<telerik:RadContextMenu ID="grPortalListMenu" runat="server" EnableRoundedCorners="true"
					EnableShadows="true" OnClientItemClicked="ItemClicked">
					<Targets>
						<telerik:ContextMenuElementTarget ElementID="_raddtGrid" />
					</Targets>
					<Items>
						<telerik:RadMenuItem Text="Sửa" Value="Edit" />
					</Items>
				</telerik:RadContextMenu>		
																
				</telerik:RadAjaxPanel>												
				<div class="clear"></div>
			</div>
		</article><!-- end of stats article -->

</asp:Content>